<template>
  <input type="text" v-model="msg">
  <el-button type="primary" @click="sendMsg()">发送</el-button>
</template>

<script setup>

import {ref} from "vue";

const clientId = 12
const targetId = 13
let websocket = null
if('WebSocket' in window){
    websocket = new WebSocket(`ws://localhost:8080/ws/${clientId}/${targetId}`)
}else{
    alert("Not support WebSocket")
}
websocket.onerror = function(event){
    console.log("WebSocket error")
}

websocket.onopen = function(event){
    console.log("WebSocket open")
}

websocket.onmessage = function(event){
    console.log("WebSocket message")
}

websocket.onclose = function(event){
    console.log("WebSocket close")
}
websocket.onbeforeunload = function(event){
    websocket.close()
}

const msg = ref('')
const sendMsg = () => {
    websocket.send(msg.value)
}

</script>

<style lang="scss" scoped>

</style>